<template>
  <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body :close-on-click-modal="false"
             v-dialogDrag>
    <div class="app-container">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddFp">新增</el-button>
        </el-col>
      </el-row>
      <el-table border v-loading="loading" :data="dataList"  ref="table"
                :max-height="tableMaxHeight">
        <el-table-column label="供应商名称" align="center" prop="supplierName" show-overflow-tooltip/>
        <el-table-column label="发票编号" align="center" prop="code"show-overflow-tooltip/>
        <el-table-column label="开票日期" align="center" prop="fpDate"/>
        <el-table-column label="开户行行号" align="center" prop="hanghao" show-overflow-tooltip/>
        <el-table-column label="银行账号" align="center" prop="zhanghao" show-overflow-tooltip/>
        <el-table-column label="开户行" align="center" prop="kaihuhang" show-overflow-tooltip/>
        <el-table-column label="开票金额" align="center" prop="kaipiao"/>
        <!--<el-table-column label="开票文件" align="center" prop="kpfile"/>-->
        <el-table-column align="center" label="开票文件" prop="kpfile" width="200">
          <template slot-scope="scope">
            <image-preview :src="scope.row.kpfile" height="60px" width="40px"></image-preview>
          </template>
        </el-table-column>
        <!--<el-table-column label="付款单文件" align="center" prop="fukuandan"/>-->
        <el-table-column align="center" label="付款单文件" prop="email" width="200">
          <template slot-scope="scope">
            <image-preview :src="scope.row.fukuandan" height="60px" width="40px"></image-preview>
          </template>
        </el-table-column>
        <el-table-column label="上传人" align="center" prop="ddSongpeople"/>
        <el-table-column label="备注" align="center" prop="remark"/>
        <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="140">
          <template slot-scope="scope">
            <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                           style="margin-left: 10px;">
              <el-button slot="reference" size="mini" type="text" icon="el-icon-delete">删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize" @pagination="getList"/>
    </div>
    <lv-fapiaoForm ref="formFapiao" @ok="getList"></lv-fapiaoForm>
  </el-dialog>
</template>

<script>
  import { getAction,deleteAction } from '@/api/manage'
  import LvFapiaoForm from "@/views/develop/lvFapiao/module/LvFapiaoForm";

  export default {
    name: "FapiaoForm",
    components: {
      LvFapiaoForm
    },
    data() {
      return {
        title: "记录",
        open: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        rows: [],
        supplierId:null,
        caigouno:null,
        kaipiao:null,
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 销售信息管理表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          cgallid:null,
          pageNum: 1,
          pageSize: 20,
          mainId: null,
          name: null,
          brand: null,
          unit: null,
          costPrice: null,
          count: null,
          cost: null,
          validityTerm: null,
          buyId: null,
          buyName: null,
          buyDate: null,
          buyType: null,
          reimburse: null,
          supplierId: null,
          supplierName: null,
          dateRange: "",
          params: {},
        },
        url: {
          list: '/lvFapiao/lvFapiao/list',
          remove:'/lvFapiao/lvFapiao/deleteById/',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      // this.intDictsForPrj();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight);
    },
    methods: {
      handleAddFp(){
        this.$refs.formFapiao.handleAdd(this.queryParams.caigouid,this.supplierId,this.caigouno,this.kaipiao);
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      showfapiao(row){
        this.queryParams.caigouid=row.id;
        this.supplierId=row.supplierId;
        this.caigouno=row.nos;
        this.kaipiao=row.shengyukp;
        this.open=true;
        this.getList();
      },
      /** 查询销售信息管理列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      handleDelete(rowd) {
        const id = rowd.id ;
        deleteAction(this.url.remove, id).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
    }
  };
</script>
